using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RiddleController : MonoBehaviour
{
    public bool isSolved = false;
    public List<Riddle> riddleList = new List<Riddle>();
    private RoomController roomCtr;
    
    private void Awake()
    {
        roomCtr = GetComponentInParent<RoomController>();
        foreach (Transform child in transform)
        {
            Riddle riddle = child.GetComponent<Riddle>();
            if (riddle) riddleList.Add(riddle);
        }
    }

    public void CheckRiddles()
    {
        foreach (var riddle in riddleList)
        {
            if (riddle.RiddleState == RiddleState.UnSolved)
            {
                isSolved = false;
                return;
            }

            isSolved = true;
        }

        if (isSolved)
        {
            roomCtr.fenceAni.SetBool("up",false);
            roomCtr.treasuresGO.SetActive(true);
        }
    }
}